package com.ycc.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycc.biz.common.PageResult;
import com.ycc.biz.common.Result;
import com.ycc.biz.pojo.entity.BizAttachment;
import com.ycc.biz.pojo.entity.BizProduct;
import com.ycc.biz.pojo.query.BizProductQuery;
import com.ycc.biz.service.BizAttachmentService;
import com.ycc.biz.service.BizProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "商品管理")
@RestController
@RequestMapping("/product")
@AllArgsConstructor
public class BizProductController {
    private final BizProductService productService;
    private final BizAttachmentService attachmentService;

    @ApiOperation("添加商品")
    @PostMapping("/add")
    public Result<Boolean> addProduct(@ApiParam("商品信息") @RequestPart BizProduct product) {
        productService.save(product);
        return Result.success(true);
    }

    @ApiOperation("删除商品")
    @PostMapping("/delete")
    public Result<Boolean> deleteProduct(@RequestParam String id) {
        return Result.success(productService.removeById(id));
    }

    @ApiOperation("更新商品")
    @PostMapping("/update")
    public Result<Boolean> updateProduct(@ApiParam("商品信息") @RequestPart BizProduct product) {
        return Result.success(productService.updateById(product));
    }

    @ApiOperation("根据ID查询商品")
    @PostMapping("/getById")
    public Result<BizProduct> getProductById(@RequestParam String id) {
        return Result.success(productService.getById(id));
    }
    
    @ApiOperation("查询所有商品")
    @PostMapping("/list")
    public Result<List<BizProduct>> listProducts() {
        return Result.success(productService.list());
    }

    @ApiOperation("分页查询商品")
    @PostMapping("/page")
    public Result<PageResult<BizProduct>> pageProducts(@RequestBody BizProductQuery query) {
        return Result.success(productService.pageProducts(query));
    }
}